<template>
	<el-dialog v-model="model" title="註銷賬號" width="450px">
		<div style="padding: 10px 16px">
			您即将注销<el-text type="primary">{{ store.profile.email }}</el-text
			>在<el-text type="primary">{{ siteUri }}</el-text
			>的账号。注销后我们将清除您的注册资料及在我方网站产生的历史数据。
		</div>
		<template #footer>
			<el-button :loading="submitting" type="primary" @click="handleLogOut">确认</el-button>
			<el-button @click="handleCancel">取消</el-button>
		</template>
	</el-dialog>
</template>
<script setup>
import { userStore } from '~/composables/store/modules/user';

const { $navigate } = useNuxtApp();
const model = defineModel({ type: Boolean });
const store = userStore();
const submitting = ref(false);

const siteUri = location.origin;

function handleCancel() {
	model.value = false;
}

async function handleLogOut() {
	submitting.value = true;
	try {
		await store.logoutAction();
        $navigate("/")
		model.value = false;
	} finally {
		submitting.value = false;
	}
}
</script>
